<?php

/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/3/28
 * Time: 14:37
 */
class Model_SharePrizeRecord extends PhalApi_Model_NotORM{
  protected function getTableName($id){
    return 't_shareprizerecord';    //商户表
  }
  /**
 * 领券红包
 */
  public function getCoupon($phone,$prizeid){
    return $this->getORM()->insert(array('userid'=>$phone,'prizeId'=>$prizeid,'createtime'=>time()));
  }
  /**
   * 检查是否今天领取红包
   */
  public function checkIsGetCoupon($phone){
    return $this->getORM()->select('count(*) count')
      ->where('userid',$phone)
      ->where('createtime<?',strtotime(date("Y-m-d",strtotime("+1 day"))))
      ->where('createtime>=?',strtotime(date("Y-m-d")))
      ->fetchOne();
  }
  /**
   * 获取今天中奖次数
   */
  public function getPrizeRecord($prizeId){
    return $this->getORM()->select('count(*) count')
      ->where('prizeId',$prizeId)
      ->where('createtime<?',strtotime(date("Y-m-d",strtotime("+1 day"))))
      ->where('createtime>=?',strtotime(date("Y-m-d")))
      ->fetchOne();
  }
}